package com.hy.usercenter.controller;

import com.hy.usercenter.model.domain.UserTeamRelation;
import com.hy.usercenter.service.UserTeamRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description
 * @Author minsf
 * @Date 2023/2/26
 */
@RestController
@RequestMapping("/user-team-relation")
@CrossOrigin(origins = {"http://localhost:5173/","http://localhost:8080", "http://127.0.0.1:5173/"},
        allowCredentials = "true",
        methods = {RequestMethod.OPTIONS,RequestMethod.GET,RequestMethod.POST}
)
public class UserTeamRelationController {

    @Autowired
    private UserTeamRelationService userTeamRelationService;

    // 查询用户-队伍关系列表
    @GetMapping("/list")
    public List<UserTeamRelation> list() {
        return userTeamRelationService.list();
    }

    // 根据ID查询用户-队伍关系信息
    @GetMapping("/{id}")
    public UserTeamRelation getById(@PathVariable Long id) {
        return userTeamRelationService.getById(id);
    }

    // 新增用户-队伍关系
    @PostMapping("")
    public boolean add(@RequestBody UserTeamRelation userTeamRelation) {
        return userTeamRelationService.save(userTeamRelation);
    }

    // 修改用户-队伍关系信息
    @PutMapping("/{id}")
    public boolean update(@PathVariable Long id, @RequestBody UserTeamRelation userTeamRelation) {
        userTeamRelation.setId(id);
        return userTeamRelationService.updateById(userTeamRelation);
    }

    // 删除用户-队伍关系
    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable Long id) {
        return userTeamRelationService.removeById(id);
    }
}
